  <div class="ns-ticker ns-wrapper grid">
    <div id="ns_content" class="container_12 edit_skills">
      <div class="grid_8 profile_content ns_edit-skills}}" id="edit-skills" style="display:block">
        <div class="ns_edit-skills">
          <p class="ns_margin-30"><h3> Hãy chọn tối đa <b><i>10 kỹ năng </i></b>của bạn trong danh sách dưới đây.
            Hãy chọn cẩn thận bởi có thể mỗi dự án yêu cầu những kỹ năng riêng.</h3></p>
        </div>
        <div class="ns_skills-box">
          <table>
          <tr>
            <td><div class="ns_right ns_pad-r20">
                <p class="ns_margin-top10 ns_bold">Total Skills</p>
                <p class="ns_bold ns_larger">
                  <span id="jl_info">
                    <?php
                      $id= Yii::app()->user->id;
                      $count = UserSkill::Model()->count("user_id=:user_id", array(":user_id" => $id));
                      //$count= Yii::app()->db->createCommand("SELECT count(*) FROM tbl_user_skill WHERE user_id=$id")->execute();
                      echo $count;
                    ?>
                  </span>
                </p>
                <p class="ns_margin-10 ns_small ns_grey-light">(Max 20)</p>
            </div>
            </td>
              <td><div class="ns_right ns_pad-120 ns_border-left">
                <p class="ns_margin-top10 ns_bold">Changes Left</p>
                <p class="ns_bold ns_larger">
                  <span id="jlc_info">5</span>
                </p>
                <p class="ns_margin-10 ns_small ns_grey-light">(5/month)</p>
              </div>
              </td>
            </tr>
          </table>
        </div>
        <div class="ns_clear"></div>

      <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'news-form',
        'enableAjaxValidation'=>false,
      )); ?>
        <ul class="menu ns_accordion">
          <?php foreach ($jobtype as $key1): ?>
          <ol class="ns_item_1">
            <span class="ns_bold"><?php echo $key1->name;?></span>
            <span class="ns_right ns_italic ns_margin-r15" style>
              <span class="subtotal">
              <?php
                $count= Yii::app()->getModule('user')->getCountJobtype($key1->id);
                if ($count >0) echo $count." selected";
              ?>
              </span>
            </span>
          </ol>

          <ol class="ns_item_2" style>
            <ul class="ns_li marginleft_5">
            <?php
              $Criteria = new CDbCriteria();
              $Criteria->condition = "jobtype_id = $key1->id";
              $sub_jobtype = SubJobtype::model()->findAll($Criteria);
              foreach ($sub_jobtype as $key2):
            ?>
            
              <ol class="ns_bold marginleft_10"><?php echo $key2->name;?></ol>
              <ol style>
                <ul>
              <?php
                $Criteria = new CDbCriteria();
                $Criteria->condition = "subjobtype_id = $key2->id";
                $skill = Skill::model()->findAll($Criteria);
                foreach ($skill as $key3): ?>
                  <ol class="ns_li_small">
                    <?php
                      $sql="SELECT id from tbl_user_skill where user_id=$id AND skill_id=$key3->id";
                      $command = Yii::app()->db->createCommand($sql)->queryScalar();
                      if($command != 0 ):
                    ?>
                    <input type="checkbox" name="skill[]" value="<?php echo $key3->id; ?>" checked/> <?php echo $key3->name; ?>
                    <?php
                      else:
                    ?>
                    <input type="checkbox" name="skill[]" value="<?php echo $key3->id; ?>" /> <?php echo $key3->name; ?>
                    <?php endif; ?>
                  </ol>
                  <div class="ns_clear"></div>
                <?php endforeach; ?>
                </ul>
              </ol>
              <div class="ns_clear"></div>
              <?php endforeach; ?>
            </ul>
            
          </ol>
          <?php endforeach; ?>
        </ul>
        <br>
        <div class="ns_clear"></div>

        <div>
          <p class="ns_margin-30"><h3> Nếu bạn có những kỹ năng khác ngoài những kỹ năng được liệt kê ở trên, hãy nhập bổ sung chúng tại đây.</h3></p>
          <?php
            $id= Yii::app()->user->id;
            $sql = "SELECT COUNT(*) FROM tbl_user_skill where user_id=$id and skill_id= 0";
            $count_add = Yii::app()->db->createCommand($sql)->queryScalar();
            $Criteria = new CDbCriteria();
            $Criteria->condition = "user_id= $id and skill_id= 0";
            $m_skill = UserSkill::model()->findAll($Criteria);
            foreach ($m_skill as $key):
          ?>
          <input type="hidden" name="id[]" value="<?php echo $key->id; ?>" />
          <input class="keyadd" name="edit[]" type="text" value= "<?php echo $key->skill_add; ?>" readonly><br/>
          <?php endforeach; ?>

          <button class="editbtn" onclick="return false;">edit</button>
        </div>

        <?php echo CHtml::dropDownList('jobtype_id','',CHtml::listData(Jobtype::model()->findAll(),'id','name'),array('prompt' => 'Chọn một lĩnh vực',
                    'ajax' => array(
                    'type'=>'POST', //request type
                    'url'=>CController::createUrl('/job/create/ajaxdropdown'),
                    'update'=>'#subjobtype_id', //selector to update
                    )));  ?>
        <select id ='subjobtype_id'></select>
        <div class="cls" id="idd"></div>

        <div class="ns_right">
          <!-- <a class="ns_btn ns_blue ns_margin-r5" href="javascript:void(0)" id="save_changes">Save Changes</a>
          <a class="ns_btn ns_margin-none" href="javascript:void(0);" id="cancel_skill_changes">Cancel</a> -->
            <?php echo CHtml::submitButton($model_skill->isNewRecord ? 'Create' : 'Save',array('class'=>'ns_btn ns_blue ns_margin-r5')); ?>
        <?php $this->endWidget(); ?>
        </div>
      </div>
    </div>
  </div>


<?php //Toàn bộ AJAX viết tại đây
      // Ajax tạo button Add ?>
<script type="text/javascript">
  $('.editbtn').click(function(){
    $('.keyadd').attr('readonly', false);
  });
</script>

<script type="text/javascript"><!--
  $(document).ready(function() {
    $('#idd').after('<button id="btn">+Add...</button>');       // insert the new button after the tag with id="idd"
    $('#btn').click(function() {
      $('#idd').append('<input type="text" size="75" placeholder="Kỹ năng bổ sung" name="Skill_add[]" maxlength="100" class="ac_input"></input>');
      return false;
    });
});
--></script>

<script type="text/javascript">
  function toggleNextByTagName(tname) {
    e.preventDefault();
    var ccn="clicker";
    var clickers=document.getElementsByTagName(tname);
    for (i=0; i<clickers.length; i++) {
    clickers[i].className+=" "+ccn;
    clickers[i].onclick=function() {toggleNext(this)}
    toggleNext(clickers[i]);
    }
  }
</script>

<script type="text/javascript">
  function toggleNext(el) {
    var next=el.nextSibling;
    while(next.nodeType != 1) next=next.nextSibling;
    next.style.display=((next.style.display=="none") ? "block" : "none");
  }
  function toggleNextById(el) {
    var ccn="clicker";
    var clicker=document.getElementById(el);
    clicker.className+=" "+ccn;
    clicker.onclick=function() {toggleNext(this)}
    toggleNext(clicker);
  }
  windows.onload=function(){toggleNextById('salutation')}
</script>


<script type="text/javascript">
  function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
  e.style.display="block"
  }
  else{
  e.style.display="none"
  }
  return true;
  }
</script>


<script type="text/javascript">
  $(function() {
  
      var menu_ul = $('.menu > li > ul'), 
             menu_a  = $('.menu > li > a');
      
      menu_ul.hide();
  
      menu_a.click(function(e) {
         
          if(!$(this).hasClass('active')) {
          //   e.preventDefault();
              menu_a.removeClass('active');
              menu_ul.filter(':visible').slideUp('normal');
              $(this).addClass('active').next().stop(true,true).slideDown('normal');

          } else {
              $(this).removeClass('active');
              $(this).next().stop(true,true).slideUp('normal');

          }
      });
  
  });
</script>